package com.to_door_recycle.handler;

import com.to_door_recycle.common.enums.ExceptionStatusEnum;
import com.to_door_recycle.common.exception.auth.AuthException;
import com.to_door_recycle.common.exception.biz.BizException;
import com.to_door_recycle.common.rest.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler({AuthException.class})
    public Response handlerAuthException(AuthException e) {
        log.error("认证异常：{}, {}", e, e.getClass());
        return Response.fail(e);
    }

    @ExceptionHandler({BizException.class})
    public Response handlerBizException(BizException e) {
        log.error("业务异常：{}, {}", e,e.getClass());
        return Response.fail(e);
    }

    @ExceptionHandler({Exception.class})
    public Response handlerException(Exception e) {
        log.error("出现异常：{}, {}", e.getCause(), e.getClass());
        return Response.fail(ExceptionStatusEnum.UNNORMAL);
    }

}
